package com.example.jack.community.view.me;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.jack.community.R;
import com.example.jack.community.view.me.adapter.MyPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的社团页面
 */
public class My_Com_Activity extends com.example.jack.community.view.me.BlackStatusActivity implements View.OnClickListener {

    private ImageView imageView;
    private TextView textView;
    private TabLayout tableLayout;
    private ViewPager mViewPager;
    private List<String> mDatas;
    private List fragments;
    private MyComFragment myComFragment = new MyComFragment();
    private MyActivityFragment myActivityFragment = new MyActivityFragment();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my__com_);
        initData();
        initFragments();
        viewpager();

    }

    private void viewpager() {
        textView = (TextView) findViewById(R.id.text_return);
        imageView = (ImageView) findViewById(R.id.back);
        tableLayout = (TabLayout) findViewById(R.id.tablayout);
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), mDatas, fragments));
        tableLayout.setupWithViewPager(mViewPager);
        imageView.setOnClickListener(this);
        textView.setOnClickListener(this);
    }

    /**
     * 加载tablelayout所需要的数据
     */
    private void initData() {
        mDatas = new ArrayList<>();
        mDatas.add(getString(R.string.join_club));
        mDatas.add(getString(R.string.join_activity));
    }

    private void initFragments() {
        fragments = new ArrayList<>();
        fragments.add(myComFragment);
        fragments.add(myActivityFragment);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.text_return:
                finish();
                break;
            case R.id.back:
                finish();
                break;
        }
    }
}
